import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:s_mankey/config/resource_mananger.dart';
import 'package:s_mankey/ui/widget/custom_button.dart';

class BindingAccount extends StatefulWidget {

  BindingAccount({Key key}) : super(key: key);

  @override
  _BindingAccountState createState() {
    return _BindingAccountState();
  }
}

class _BindingAccountState extends State<BindingAccount> {

  TextEditingController _unameController = new TextEditingController();
  TextEditingController _pwdController = new TextEditingController();
  GlobalKey _formKey= new GlobalKey<FormState>();
  var list = ['+86', '+852', '+853'];

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(appBar: AppBar(title:  Text('绑定彩析帐号'),),body: Form(
      key: _formKey, //设置globalKey，用于后面获取FormState
      autovalidate: true, //开启自动校验
      child: Column(
        children: <Widget>[
          Container(
            padding: EdgeInsets.only(top: 40),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.only(top: 8),
                  child:

                    GestureDetector(onTap:  () {
                      showModalBottomSheet(
                          context: context,
                          builder: (BuildContext context){
                            return new Column(
                              mainAxisSize: MainAxisSize.min,
                              children: List.generate(list.length, (index){
                                return  new ListTile(
                                  leading: new Icon(Icons.photo_camera),
                                  title: new Text(list[index]),
                                  onTap: () async {
//                      imageFile = await ImagePicker.pickImage(source: ImageSource.camera);
                                    Navigator.pop(context);
                                  },
                                );
                              }),

                            );
                          }
                      );
                    },child:Row(children: <Widget>[ Text('+86'),
                    Icon(Icons.arrow_drop_down, ),
                  ],),
                ),),
                Container(
                  margin: EdgeInsets.only(left: 10),
                  width: 220,
                  child: TextFormField(
                      autofocus: true,
                      controller: _unameController,
                      decoration: InputDecoration(
//                    labelText: "手机号码",
                        hintText: "请输入手机号码",
                      ),
                      // 校验用户名
                      validator: (v) {
                        return v
                            .trim()
                            .length > 0 ? null : "手机号码不能为空";
                      }

                  ),
                ),
              ],),
          ),
          Container(
            padding: EdgeInsets.only(top: 10),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Container(
                  width: 180,
                  child: TextFormField(
                      controller: _pwdController,
                      decoration: InputDecoration(
                        labelText: "请输入验证码",
                      ),
                      obscureText: true,
                      //校验密码
                      validator: (v) {
                        return v
                            .trim()
                            .length > 5 ? null : "密码不能少于6位";
                      }
                  ),
                ),
                GestureDetector(onTap: (){
                  print('发送验证码');
                },child:  CustomButton(
                    padding: EdgeInsets.fromLTRB(15, 5, 15, 5),
                    margin: EdgeInsets.only(left: 10),
                    title: '发送验证码',
                    fontSize: AppFontSize.Size12,
                    fontColor: Colors.white,
                    radius: 10.0,
                    borderColor: Colors.transparent,
                    gradient:AppColor.gradientColorHigh),),
              ],
            ),
          ),

          /// 点击绑定
          GestureDetector(onTap: (){
            print('点击登录了');
            //在这里不能通过此方式获取FormState，context不对
//              print(Form.of(context));
//
//              // 通过_formKey.currentState 获取FormState后，
//              // 调用validate()方法校验用户名密码是否合法，校验
//              // 通过后再提交数据。
            if((_formKey.currentState as FormState).validate()){
              print('FormState${FormState}');
            }else{
              print('没有拿到值');
            }
//                //验证通过提交数据
          },child:  CustomButton(
              margin: EdgeInsets.only(top: 20),
              padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
              widgt: 250.0,
              title: '登录',
              fontSize: AppFontSize.Size18,
              fontColor: Colors.white,
              radius: 30.0,
              borderColor: Colors.transparent,
              gradient:AppColor.gradientColorHigh),),

        ],
      ),
    ),
    );
  }
}

